
import { Config } from '../../utils/config.js';
import { Fenxiao } from './fenxiao-model.js';
var fenxiao = new Fenxiao();
Page({
  data: {
    statusType: ["全部", "已完成", "未完成"],
    currentTpye: 0,
    page: 1,
    hiddenNomore: true,
    hiddenLoading: true,
    hiddenNullData: true,
    onLoading: false,
    nomore: false,
    shareText: '转赠',
  },
  onLoad: function (options) {
    var index = options.index ? options.index : 0;
    //初始化
    this.setData({
      currentTpye: index
    })
    this._getData();
  },
  //顶部选项切换
  typeTap: function (e) {
    var curType = e.currentTarget.dataset.index;
    this.data.currentTpye = curType
    //重置数据
    this.setData({
      currentTpye: curType,
      items: [],
      hiddenNullData: true
    });
    this.data.page = 1;
    this.data.nomore = false;
    this._getData();
  },
  /*获取分销订单*/
  _getData: function () {
    var that = this;
    var args = {
      page: this.data.page,
      num: 15,
      status: that.data.currentTpye
    }
    that.setData({
      hiddenLoading: false
    })
    fenxiao.getOrders(args, (res) => {
      if (that.data.page == 1) {
        that.data.items = [];
      }
      var items = res.items;
      var items = that.data.items.concat(items);
      that.setData({
        items
      })
      //隐藏正在加载中
      that.setData({
        hiddenLoading: true
      })
      if (items.length == 0) {
        //显示没有数据
        that.setData({
          hiddenNullData: false
        })
      }
      if (that.data.page >= res._meta.pageCount) {
        that.data.nomore = true;
        if (that.data.page > 1) {
          //显示没有更多
          that.setData({
            hiddenNomore: false
          })
        }
      }
    });
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.nomore) {
      return false;
    }
    this.data.page++;
    this._getData();
  },
})